#include "Shader.h"

Shader::Shader(CGcontext context, CGprofile profile, const char *filename)
{
	this ->context = context;
	this ->profile = profile;
	
	std::ifstream file(filename, std::ios::binary);

	file.seekg(0, std::ios::end);
	int fileSize = file.tellg();
	file.seekg(0, std::ios::beg);

	char *code = new char[fileSize + 1];
	code[fileSize] = 0;
	file.read(code, fileSize);
	file.close();

	programId = cgCreateProgram(context, CG_SOURCE, code, profile, "main", NULL);
	const char *zlo = cgGetErrorString(cgGetError());
	cgGLLoadProgram(programId);

	delete [] code;
}

Shader::~Shader(void)
{
	if (programId != NULL)
		cgDestroyProgram(programId);
}

void Shader::DoShader()
{
	cgGLEnableProfile(profile);
	cgGLBindProgram(programId);
}

CGprofile Shader::GetProfile()
{
	return profile;
}

CGprogram Shader::GetProgram()
{
	return programId;
}
